/**
 * Created by WangMing on 15/12/9.
 */
define(["../../../service",
  "../../../widgets/breadcrumb_widget/breadcrumb_widget"], function (api) {
  // 定义所有相关的vmodel
  var vm = avalon.define({
      $id: "weike",
      $album: {},
      $name:"fuck",
      albumVideos: {},
      params: {

            type: "weike",
            method: api.getAlbum,
            query:{
                guid: "",
                order: null
            }

      },
      $breadcrumb: {
        stateName:"albums.item",
        guid: "",
        title: ""
      },
      
      displayPage:function(state){
        return state.vmName == "weike";
      },
      $skipArray : ["breadcrumbWidget","params","albumVideos"]
    });
  

  return avalon.controller(function ($ctrl) {

    // 视图渲染后，意思是avalon.scan完成
    $ctrl.$onRendered = function () {
     
    };
    // 进入视图
    $ctrl.$onEnter = function (param, rs, rj) {
      
      api.getItems({
            type: "album",
            method: api.getAlbum,
            query:{
                guid: param.itemID,
                order: null
            }
      },function(res){
        if(_.isArray(res)){
          vm.$album = _.merge(vm.$album,res[0]);
        }else{
          vm.$album = _.merge(vm.$album,res);
        }
        
        vm.albumVideos = {
          results: {
            collections: vm.$album.videos,
            size: (vm.$album.videos&&vm.$album.videos.length)||0,
            total:(vm.$album.videos&&vm.$album.videos.length)||0
          },
          isAjax:false
        };

        vm.$album.albumVideos = vm.albumVideos;

        vm.$breadcrumb.title = vm.$album.title;
      })
    };
    // 对应的视图销毁前
    $ctrl.$onBeforeUnload = function () {

    };
    $ctrl.$vmodels = [vm];
  })
});